/**
 * @description 地址数据操作
 * @author boen
 */

const Address = require('../../models/Address')

    !(async () => {
        // 创建收货地址
        // await Address.create({
        //     username:'boen',
        //     city: '成都',
        //     department: '锦地苑',
        //     houseNumber: '9-224',
        //     name: 'boen',
        //     phone: '123123123'
        // })

        // 获取某人的收货地址列表  -- 逆序
        // const res = await Address.find({
        //     username: 'boen'
        // }).sort({ updatedAt: -1 })
        // console.log(res);

        // 根据收货地址id 获取单个收货地址
        // const id = '61c194addf063696612554e1'
        // const res = await Address.findById(id)

        // console.log(res);

        // 更新收货地址
        const id = '61c194addf063696612554e1'
        const newData = {
            city: '浙江',
            department: '皮革厂',
            houseNumber: '99',
            name: '小智',
            phone: '157820'
        }
        const res = await Address.findOneAndUpdate({
            _id: id
        },newData,{
            new: true
        })

        console.log(res);

    })()